﻿
using System.Collections.Generic;

namespace Enferno.Public.Web.Models
{

    public class ProductModel : ProductWithCustomVariantModel<VariantModel>
    {
        
    }

    public class ProductWithCustomVariantModel<TVariant> :
        ProductBaseModel<
        TVariant, 
        ProductManufacturerModel,
        ProductListCustomVariantModel<TVariant, ProductItemCustomVariantModel<TVariant>>,
        ProductItemCustomVariantModel<TVariant>,
        FilterModel,
        ProductFileModel,
        PriceModel, 
        OnHandStatusModel, 
        ParametricModel, 
        ParametricValueModel>
        where TVariant : VariantBaseModel<OnHandStatusModel, PriceModel, ProductFileModel, ParametricModel, ParametricValueModel>
    {
        
    } 

    public class ProductBaseModel<
        TVariantModel, 
        TProductManufacturerModel, 
        TProductListModel, 
        TProductItemModel, 
        TFilterModel,
        TProductFileModel, 
        TPriceModel, 
        TOnHandStatusModel, 
        TParametricModel, 
        TParametricValueModel>
        where TVariantModel: VariantBaseModel<TOnHandStatusModel, TPriceModel, TProductFileModel, TParametricModel, TParametricValueModel>
        where TProductManufacturerModel: ProductManufacturerModel
        where TProductListModel: ProductListBaseModel<TProductItemModel, TFilterModel, TVariantModel, TProductFileModel, TProductManufacturerModel, TPriceModel, TOnHandStatusModel, TParametricModel, TParametricValueModel> 
        where TProductItemModel: ProductItemBaseModel<TVariantModel, TProductFileModel, TProductManufacturerModel, TPriceModel, TOnHandStatusModel, TParametricModel, TParametricValueModel>
        where TFilterModel: FilterModel
        where TProductFileModel: ProductFileModel
        where TPriceModel: PriceModel
        where TOnHandStatusModel: OnHandStatusModel
        where TParametricModel : ParametricBaseModel<TParametricValueModel>
        where TParametricValueModel : ParametricValueModel
    {
        public ProductBaseModel()
        {
            Variants = new List<TVariantModel>();
            Flags = new List<int>();
            Files = new List<TProductFileModel>();
            Families = new List<ProductFamilyModel>();
            VariantParametrics = new List<TParametricModel>();
            Parametrics = new List<TParametricModel>();
            Products = new Dictionary<string, TProductListModel>();
        }

        public int Id { get; set; }

        public string Name { get; set; }
        public string UniqueName { get; set; }
        public string SubHeader { get; set; }
        public string DescriptionHeader { get; set; }
        public string Description { get; set; }
        public string UnitOfMeasurement { get; set; }

        public int StatusId { get; set; }
        public string MetaTags { get; set; }
        public string MetaDescription { get; set; }
        public int? StockDisplayBreakPoint { get; set; }
        public bool IsBuyable { get; set; }

        public List<TVariantModel> Variants { get; set; }
        public TVariantModel SelectedVariant { get; set; }   
        
        public TProductManufacturerModel Manufacturer { get; set; }
        public ProductCategoryModel Category { get; set; }
        
        public List<int> Flags { get; set; }

        public decimal RecommendedQuantity { get; set; }
        public bool IsRecommendedQuantityFixed { get; set; }

        public List<TProductFileModel> Files { get; set; }
        public List<ProductFamilyModel> Families { get; set; }

        private PriceModel price;
        public PriceModel Price
        {
            get { return SelectedVariant != null ? SelectedVariant.Price : price; }
            set { price = value; }
        }

        private TOnHandStatusModel onHandStatus;
        public TOnHandStatusModel OnHandStatus
        {
            get { return SelectedVariant != null ? SelectedVariant.OnHandStatus : onHandStatus; }
            set { onHandStatus = value; }
        }

        public List<TParametricModel> VariantParametrics { get; set; }
        public List<TParametricModel> Parametrics { get; set; }

        /// <summary>
        /// Can be used to add ProductListModels such as Accessories or other lists. Just tag the list with a suitable name.
        /// </summary>
        public Dictionary<string, TProductListModel> Products { get; set; } 
    }
}
